package DailyPractice.Day10;

/**
 * 判断井字棋是否获胜
 * @author lumin
 * @date 2022/04/28 13:48
 **/
public class Num1 {
    public static boolean checkWon(int[][] board) {
        // write code here
        int m = board.length;
        int n = board[0].length;
        if(board[0][0] + board[1][1] + board[2][2] == 3 || board[0][2] + board[1][1] + board[2][0] == 3){
            return true;
        }
        int i = 0;
        while (i < m) {
            int j = 0;
            int sum = 0;
            while (j < n) {
                sum += board[i][j];
                j++;
            }
            if (sum == 3) {
                return true;
            }
            i++;
        }
        int i1 = 0;
        while (i1 < m) {
            int j = 0;
            int sum = 0;
            while (j < n) {
                sum += board[j][i1];
                j++;
            }
            if (sum == 3) {
                return true;
            }
            i1++;
        }
        return false;
    }

    public static void main(String[] args) {
        int[][] arr = {{1,0,1},{1,-1,-1},{1,-1,0}};
        System.out.println(checkWon(arr));
    }
}